﻿@model YunShop.Models.BillModel
@{
    ViewBag.Title = "打印";
}
@section scripts
{
    <link href="@Url.Content("~/content/css/kingprt.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/content/css/font-awesome.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.PrintArea.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/Base/print.js?v=20240412152")" type="text/javascript"></script> 
}
<div class="prtTools">
    <div class="tool">
        <a href="#" class="button fa-print btnPrint">打印</a>
        <!--<a href="#" class="button next">关闭</a>-->
    </div>
</div>
<input type="hidden" id="PrtTitle" name="PrtTitle" value="" />
<script>
    var Grid=null;
    function GreateTable() {
        $(".btnPrint").click(function () {
            $(".A4_verPrint").printArea();
        });
        $(".next").click(function () {
            mini.confirm("确定要删除选中的记录吗？", "提示",
            function (action) {
                if (action == "ok") {
                    window.opener = null;
                    window.open('', '_self');
                    window.close();
                }
            });
        });
        $.post("../Bill/GetPrtData", {}, function (data) {
            if (Grid == null) {
                colTitle = [{ text: "序号", width: "0.5cm", align: "alignCenter", field: "mFRowNo", format: "" },
                    { text: "商品条码", width: "2.5cm", align: "alignLeft", field: "mFCode", format: "" },
                    { text: "商品名称", width: "3cm", align: "alignLeft", field: "mFName", format: "" },
                    { text: "规格", width: "1.8cm", align: "alignLeft", field: "mFModel", format: "" },
                    { text: "单位", width: "1cm", align: "alignLeft", field: "mFUnitName", format: "" },
                    { text: "数量", width: "1cm", align: "alignRight", field: "mFQty", format: "#,0.00" },
                    { text: "赠送数量", width: "1.7cm", align: "alignRight", field: "mFSetQty", format: "#,0.00" },
                    { text: "单价", width: "1cm", align: "alignRight", field: "mFPrice", format: "#,0.00" },
                    { text: "金额", width: "1cm", align: "alignRight", field: "mFAmount", format: "#,0.00" },
                    { text: "备注", width: "1.5cm", align: "alignLeft", field: "mFRemark", format: "" }];
            }
            else {
                var columns = Grid.getColumns();
                columns = columns.clone();
                for (var i = 0; i < columns.length; i++) {
                    var cols = [];
                    if (columns[i].columns == undefined)
                        cols[0] = columns[i];
                    else
                        cols = columns[i].columns;
                    for (var j = 0; j < cols.length; j++) {
                        var column = cols[j];
                        var width = parseFloat(column.width.replace('px', ''));
                        switch (Trim(column.header)) {
                            case "序号": if (width > 10) colTitle.push({ text: "序号", width: "0.5cm", align: "alignCenter", field: "mFRowNo", format: "" }); break;
                                //case "商品编码": if (width > 10) colTitle.push({ text: "商品编码", width: "2.5cm", align: "alignLeft", field: "mFNumber", format: "" }); break;
                            case "商品编码": if (width > 10) colTitle.push({ text: "商品条码", width: "2.5cm", align: "alignLeft", field: "mFCode", format: "" }); break;
                            case "商品名称": if (width > 10) colTitle.push({ text: "商品名称", width: "3cm", align: "alignLeft", field: "mFName", format: "" }); break;
                            case "规格型号": if (width > 10) colTitle.push({ text: "规格", width: "1.8cm", align: "alignLeft", field: "mFModel", format: "" }); break;
                            case "单位": if (width > 10) colTitle.push({ text: "单位", width: "1cm", align: "alignLeft", field: "mFUnitName", format: "" }); break;
                            case "数量": if (width > 10) colTitle.push({ text: "数量", width: "1cm", align: "alignRight", field: "mFQty", format: "#,0.00" }); break;
                            case "赠送数量": if (width > 10) colTitle.push({ text: "赠送", width: "1cm", align: "alignRight", field: "mFSetQty", format: "#,0.00" }); break;
                            case "要货数量": if (width > 10) colTitle.push({ text: "数量", width: "1cm", align: "alignRight", field: "mFQty", format: "#,0.00" }); break;
                            case "采购数量": if (width > 10) colTitle.push({ text: "数量", width: "1cm", align: "alignRight", field: "mFQty", format: "#,0.00" }); break;
                            case "单价": if (width > 10) colTitle.push({ text: "单价", width: "1cm", align: "alignRight", field: "mFPrice", format: "#,0.00" }); break;
                            case "金额": if (width > 10) colTitle.push({ text: "金额", width: "1.3cm", align: "alignRight", field: "mFAmount", format: "#,0.00" }); break;
                            case "配送单价": if (width > 10) colTitle.push({ text: "配送单价", width: "1cm", align: "alignRight", field: "mFPrice", format: "#,0.00" }); break;
                            case "配送金额": if (width > 10) colTitle.push({ text: "配送金额", width: "1cm", align: "alignRight", field: "mFAmount", format: "#,0.00" }); break;
                            case "零售单价": if (width > 10) colTitle.push({ text: "零售单价", width: "1cm", align: "alignRight", field: "mFPosPrice", format: "#,0.00" }); break;
                            case "零售金额": if (width > 10) colTitle.push({ text: "零售金额", width: "1cm", align: "alignRight", field: "mFPosAmount", format: "#,0.00" }); break;
                            //case "商品条码": if (width > 10) colTitle.push({ text: "商品条码", width: "2.5cm", align: "alignLeft", field: "mFCode", format: "" }); break;
                            case "备注": if (width > 10) colTitle.push({ text: "备注", width: "1.5cm", align: "alignLeft", field: "mFRemark", format: "" }); break;
                        }
                    }
                }
            }
            header = true;
            footer = true;
            $("body").append(getHtml(data,$("#PrtTitle").val())); //生成
        });

    };

    function SetClassData(data, grid) {
        if (grid != undefined)
            Grid = grid;        
        $("#PrtTitle").val(data.title);
        GreateTable();
    }

    function Trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }
</script>